--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_x_komeiji_koishi = General:new(extension, "hy_x_komeiji_koishi", "x_k", 3, 3, General.Female)
    local empty_ego = fk.CreateSkill {
        name = "empty_ego",
    }
    empty_ego:addEffect(fk.AfterCardsMove, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and player.phase ~= Player.Draw and table.any(data, function(move)
                return move.to and move.to == player and move.toArea == Card.PlayerHand
            end)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            for _, move in ipairs(data) do
                if move.to and move.to == player and move.toArea == Card.PlayerHand then
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId)
                        room:setCardMark(card, "@@card_publicize", 1)
                    end
                end
            end
            HY.UpdatePublicizedCards(room)
        end,
    })
    empty_ego:addEffect(fk.EventPhaseStart, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and player.phase == Player.Start and #player:getCardIds("h") ~= player.maxHp
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if #player:getCardIds("h") < player.maxHp then
                room:drawCards(player, player.maxHp - #player:getCardIds("h"), empty_ego.name)
            else
                room:askToDiscard(player, {
                    min_num = #player:getCardIds("h") - player.maxHp,
                    max_num = #player:getCardIds("h") - player.maxHp,
                    skill_name = empty_ego.name,
                    cancelable = false,
                })
            end
            HY.UpdatePublicizedCards(room)
        end,
    })
    local eliminate_thoughts = fk.CreateSkill {
        name = "eliminate_thoughts",
    }
    eliminate_thoughts:addEffect("active", {
        anim_type = "support",
        card_num = 1,
        target_num = 0,
        times = function(self, player)
            return 2 - player:usedSkillTimes(eliminate_thoughts.name, Player.HistoryPhase)
        end,
        can_use = function(self, player)
            return player:usedSkillTimes(eliminate_thoughts.name, Player.HistoryPhase) < 2 and player.phase == Player.Play and (table.any(player:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@card_publicize") > 0
            end) or #player:getCardIds("e") > 0)
        end,
        card_filter = function(self, player, to_select, selected)
            if #selected == 0 then
                return table.contains(player:getCardIds("e"), to_select) or Fk:getCardById(to_select):getMark("@@card_publicize") > 0
            end
        end,
        target_filter = Util.FalseFunc,
        prompt = function(self, player, selected_cards, selected_targets)
            local value = 1 + math.floor((player:usedSkillTimes(eliminate_thoughts.name, Player.HistoryGame)) / 2)
            return "eliminate_thoughts_prompt:::" .. tostring(value)
        end,
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            room:throwCard(cardUseEvent.cards, eliminate_thoughts.name, player, player)
            room:damage({
                damage = 1 + math.floor((player:usedSkillTimes(eliminate_thoughts.name, Player.HistoryGame) - 1) / 2),
                to = player,
                damageType = fk.NormalDamage,
                skillName = eliminate_thoughts.name,
            })
            room:setPlayerMark(player, "@eliminate_thoughts", 1 + math.floor((player:usedSkillTimes(eliminate_thoughts.name, Player.HistoryGame)) / 2))
            if not player.dead then
                local target = room:askToChoosePlayers(player, {
                    targets = table.filter(room.alive_players, function(t)
                        return t:isWounded()
                    end),
                    min_num = 1,
                    max_num = 1,
                    prompt = "eliminate_thoughts_recover_prompt",
                    skill_name = eliminate_thoughts.name,
                    cancelable = false
                })
                room:recover({
                    who = target[1],
                    num = 2,
                    recoverBy = player,
                    skillName = eliminate_thoughts.name,
                })
            end
            HY.UpdatePublicizedCards(room)
        end
    })
    local abandon_memory = fk.CreateSkill {
        name = "abandon_memory",
    }
    abandon_memory:addEffect(fk.Damaged, {
        anim_type = "control",
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(self) and target == player then
                event:setSkillData(self, "cancel_cost", nil)
                for i = 1, data.damage, 1 do
                    if event:getSkillData(self, "cancel_cost") then
                        break
                    end
                    self:doCost(event, target, player, data)
                end
            end
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            event:setCostData(self, table.map(room:askToChoosePlayers(player, {
                targets = room.alive_players,
                min_num = 1,
                max_num = 1,
                prompt = "abandon_memory_prompt",
                skill_name = abandon_memory.name
            }), Util.IdMapper))
            if #event:getCostData(self) > 0 then
                return true
            end
            event:setSkillData(self, "cancel_cost", true)
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local skillTarget = room:getPlayerById(event:getCostData(self)[1])
            local targets = table.filter(room.alive_players, function(t)
                return skillTarget:inMyAttackRange(t)
            end)
            if #targets == 0 or skillTarget:isKongcheng() then
                local cards = table.filter(skillTarget:getCardIds("h"), function(id)
                    return not HY.IsCardPublicized(Fk:getCardById(id))
                end)
                if #cards > 0 then
                    room:throwCard(cards, abandon_memory.name, skillTarget, skillTarget)
                end
                room:drawCards(skillTarget, 2, abandon_memory.name)
            else
                local results = room:askToYiji(skillTarget, {
                    cards = skillTarget:getCardIds("h"),
                    targets = targets,
                    skill_name = abandon_memory.name,
                    min_num = 0,
                    max_num = #skillTarget:getCardIds("h"),
                    prompt = "abandon_memory_distribution_prompt"
                })
                if not table.any(results, function(value)
                        return #value > 0
                    end) then
                    local cards = table.filter(skillTarget:getCardIds("h"), function(id)
                        return not HY.IsCardPublicized(Fk:getCardById(id))
                    end)
                    if #cards > 0 then
                        room:throwCard(cards, abandon_memory.name, skillTarget, skillTarget)
                    end
                    room:drawCards(skillTarget, 2, abandon_memory.name)
                end
            end
            HY.UpdatePublicizedCards(room)
        end
    })
    extension:loadSkillSkels { empty_ego, eliminate_thoughts, abandon_memory }
    hy_x_komeiji_koishi:addSkill("empty_ego")
    hy_x_komeiji_koishi:addSkill("eliminate_thoughts")
    hy_x_komeiji_koishi:addSkill("abandon_memory")
    Fk:loadTranslationTable {
        ["hy_x_komeiji_koishi"] = "古明地恋",
        ["#hy_x_komeiji_koishi"] = "集体潜意识",
        ["illustrator:hy_x_komeiji_koishi"] = "しぃたけ",
        ["designer:hy_x_komeiji_koishi"] = "黑曜人形",
        ["cv:hy_x_komeiji_koishi"] = "",

        ["empty_ego"] = "空我",
        [":empty_ego"] = "你<a href='hy_card_publicize'>明置</a>于摸牌阶段外获得的牌。准备阶段，你将手牌调整至体力上限。",

        ["eliminate_thoughts"] = "清念",
        [":eliminate_thoughts"] = "出牌阶段限两次，你可以弃置一张<a href='hy_card_publicize'>明置</a>的牌并受到X点伤害，然后令一名角色回复2点体力（X为此技能发动过的次数/2+1，向下取整）。",
        ["@eliminate_thoughts"] = "清念",
        ["eliminate_thoughts_prompt"] = "清念：你可以弃置一张明置的牌并受到%arg点伤害",
        ["eliminate_thoughts_recover_prompt"] = "清念：令一名角色回复2点体力",

        ["abandon_memory"] = "舍忆",
        [":abandon_memory"] = "在你受到1点伤害后，你可以令一名角色选择一项：1.依次执行弃置所有暗置手牌，摸两张牌；2.为其攻击范围内至少一名角色分配至少一张牌。",
        ["abandon_memory_prompt"] = "舍忆：你可以令一名角色弃摸牌或交出牌",
        ["abandon_memory_distribution_prompt"] = "舍忆：你须分配手牌，否则将弃置所有暗置手牌并摸两张牌",
    }
end
